#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QString>
#include <QTextEdit>
#include <QDialog>
#include "DockManager.h"
#include <QThread>
#include "usbcommunication.h"
#include "commandprocess.h"
#include <QPushButton>
#include <QLabel>

#if defined Q_OS_WIN
#include <Windows.h>
#include <Dbt.h>
#include <devguid.h>
// 具体的设备 GUID 需要 initguid, 如 usbiodef
#include <initguid.h>
// USB 设备
// GUID_DEVINTERFACE_USB_DEVICE
#include <usbiodef.h>
// HID 人机交互设备-鼠标键盘等
#include <hidclass.h>
// 键盘 GUID_DEVINTERFACE_KEYBOARD
#include <ntddkbd.h>
// 鼠标 GUID_DEVINTERFACE_MOUSE
#include <ntddmou.h>
#endif

#define QDEBUG_REDIRECTION  1

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

///////////////////////////////////////////////////
#if (defined QDEBUG_REDIRECTION) && (QDEBUG_REDIRECTION)
public:
    static void customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
    {
        if(myMsg)
        {
            emit myMsg->sig_send_message_static(type,msg);
        }
    }

private:
    static MainWindow *myMsg;
signals:
    // void sig_send_message(const QString &msg);
    void sig_send_message_static(QtMsgType type,const QString &msg);
private slots:
    void append_text_static(QtMsgType type,const QString &text)
    {
        if(myMsg)
        {
            emit myMsg->append_message(type,text);
        }
    }
#endif
///////////////////////////////////////////////////

#if defined Q_OS_WIN
protected:
    virtual bool nativeEvent(const QByteArray &eventType,void *message,long long *result) override;

    bool RegisterUSBDeviceNotification(void);
#endif

private:
    virtual void closeEvent(QCloseEvent* event) override;
private:
    ads::CDockManager* m_DockManager;
    USBCommunication *usb_communication;
    CommandProcess *command_process;
    QPushButton *btn_open_device;
    QLabel *lab_device_info;
signals:
    void show_status_bar_message(const QString &message,int timeout = 0);
    void usb_device_change(bool is_arrival,uint16_t vid,uint16_t pid,const QString &serial_number);
    void append_message(QtMsgType type,const QString &message);
public slots:

private slots:
    void usb_device_is_connect(void);
    void usb_device_is_disconnect(void);
    void btn_click_open_device(void);

};
#endif // MAINWINDOW_H
